package com.ibm.cognos.imt.fm

import groovy.json.JsonBuilder
import groovy.json.JsonOutput

/**
 * Created by eric on 8/21/2014.
 */
class CognosModel {
    List<NameSpace> namespaces = new ArrayList<>();
    String pkg;
    String name;
    XmlSlurper slurper = new XmlSlurper()


    public List<NameSpace> getNamespaces() {
        return namespaces;
    }

    public String getPkg() {
        return pkg;
    }

    public String getName() {
        return name;
    }

    public CognosModel(String modelXmlString) {
        def project = slurper.parseText(modelXmlString)
        project.namespace.each{
            def namespace = new NameSpace(it)
            namespaces<< namespace
        }

        def pkgs = project.packages.package.name.findAll{
            it.@locale.text() == 'en'
        }
        pkg = pkgs[0].text();
        name = project.name.text();
//        println ns.size()

    }

    public String toJson() {
        def json = new JsonBuilder(this)
        String jsonStr = JsonOutput.prettyPrint(json.toString())
        println(jsonStr)
        return jsonStr;

    }
}
